package com.goldgov.mobile;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.goldgov.authorityInfo.service.AuthorityInfoInit;
import com.goldgov.conference.service.Conference;
import com.goldgov.conference.service.ConferenceAttendance;
import com.goldgov.conference.service.ConferenceAttendanceService;
import com.goldgov.conference.service.ConferenceBean;
import com.goldgov.conference.service.ConferenceQuery;
import com.goldgov.conference.service.ConferenceService;
import com.goldgov.conference.service.ConferenceStat;
import com.goldgov.conference.service.ConferenceStatQuery;
import com.goldgov.conference.service.ConferenceStatService;
import com.goldgov.conference.service.ConferenceUser;
import com.goldgov.conference.service.ConferenceUserQuery;
import com.goldgov.conference.service.ConferenceUserService;
import com.goldgov.distancelearning.service.Distancelearning;
import com.goldgov.distancelearning.service.DistancelearningBean;
import com.goldgov.distancelearning.service.DistancelearningQuery;
import com.goldgov.distancelearning.service.DistancelearningService;
import com.goldgov.kcloud.core.json.JsonQueryObject;
import com.goldgov.kcloud.core.json.JsonSuccessObject;
import com.goldgov.login.web.model.LoginAuthUser;
import com.goldgov.ms.adapter.call.RemoteCallService;
import com.goldgov.notice.service.NoticeQuery;
import com.goldgov.notice.service.NoticeService;
import com.goldgov.securityworkbench.attachment.AttachementBean;
import com.goldgov.utils.DataUtil;
import com.goldgov.utils.DateUtil;
import com.goldgov.utils.PrintUtil;
import com.goldgov.utils.PropertyUtil;
import com.goldgov.utils.UrlUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 
 * @<三会一课手机服务接口>
 * 
 * @author MaN
 * @version 1.0.0
 *
 */

@RestController
@RequestMapping("/mobile/conference")
@Api("三会一课手机服务接口")
public class ConferenceForMobileController {

	@Autowired
	private ConferenceService conferenceService;

	// 回执/会议记录与用户关系 服务接口
	@Autowired
	private ConferenceUserService conferenceUserService;

	// 考勤记录服务接口
	@Autowired
	private ConferenceAttendanceService conferenceAttendanceService;

	@Autowired
	private RemoteCallService remoteCallService;

	@Autowired
	private ConferenceStatService conferenceStatService;

	@Autowired
	private NoticeService noticeService;

	@Autowired
	private DistancelearningService distancelearningService;

	/**
	 * 预新增
	 * 
	 * @param obj
	 * @param request
	 * @return
	 */

	@GetMapping("/preAddConference")
	@ApiOperation(value = "预新增会议", notes = "查询返回会议ID")
	public JsonSuccessObject<Conference> preAddConference(Conference obj, HttpServletRequest request) {
		obj = conferenceService.getConferenceID();
		JsonSuccessObject<Conference> returnResult = new JsonSuccessObject<Conference>(obj);
		return returnResult;
	}

	@PostMapping
	@ApiOperation(value = "新增会议", notes = "新增会议记录")
	public void addConference(Conference obj, HttpServletRequest request, HttpServletResponse response, Model model
	// @ApiParam(value = "userIDs", required = true) @RequestParam("ids") String[]
	// ids,
	// @ApiParam(value = "conferenceTypes", required = true)
	// @RequestParam("conferenceTypes") String[] conferenceTypes
	) {
		LoginAuthUser u = LoginAuthUser.getUser(request);
		obj.setUserID(u.getEntityID());// 发布人
		obj.setUserName(u.getName());// 发布人姓名
		// 会议类型
		obj.setConferenceType(StringUtils.join(obj.getConferenceTypes(), ","));
		// 设置会议开始时间
		String time = obj.getConferenceBeginDate();
		if (null != time && !time.equals("")) {
			// 设置当前年份
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date conferenceBeginTime;
			try {
				conferenceBeginTime = sdf.parse(obj.getConferenceBeginDate());
				String year = String.valueOf(DateUtil.getYear(conferenceBeginTime));
				obj.setYear(year);
				// 设置季度
				obj.setQuarter(DateUtil.getSeason(conferenceBeginTime));
			} catch (ParseException e) {
				e.printStackTrace();
			}

		}
		if (obj.getLastModifiedDate() == null || obj.getLastModifiedDate().equals("")) {
			// 最后修改时间
			obj.setLastModifiedDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		}
		if (obj.getCreateDate() == null || obj.getCreateDate().equals("")) {
			// 创建时间
			obj.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		}
		// 移动端默认已发布，会议已启用
		obj.setActiveState(ConferenceQuery.ACTIVESTATE_YES);
		if (obj.getPublishState() != null && obj.getPublishState().intValue() == 1) {
			// 发布时间
			obj.setPublishDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		}
		if (obj.getOrganizationId() == null || "".equals(obj.getOrganizationId())) {
			obj.setOrganizationId(conferenceService.getOrgIdByUserId(u.getEntityID()));
		}
		String notice = request.getParameter("notice");
		if (null != notice && !"".equals(notice)) {
			obj.setIsSend(notice);
		}
		conferenceService.addConference(obj);
		try {
			// 添加人员
			if (null != obj.getUserIDs() && obj.getUserIDs().length > 0) {
				ConferenceUser user = new ConferenceUser();
				user.setPeopleNum(obj.getUserIDs().length);
				user.setUserIDs(obj.getUserIDs());
				user.setConferenceID(obj.getConferenceID());
				conferenceService.addConferenceUser2(user);
			}
			
			// 复制到远程教育
			try {
				if (obj.getConferenceType().equals("5")) {
					this.addOrUpdateDistancelearning(obj, 1, 1, request, response);
				}else {
					// 判断是否需要发送通知 1需要 2不需要
					if (null != notice && !"".equals(notice)) {
						obj.setIsSend(notice);
						if ("1".equals(obj.getIsSend())) {
							if (PropertyUtil.objectNotEmpty(obj.getPublishState()) && obj.getPublishState().intValue() == 1) {
								// 执行发送通知的逻辑
								if (obj.getUserIDs().length > 0) {
									if (!noticeService.sendNotice(obj, NoticeQuery.NOTICE_ADD)) {
										PrintUtil.printMsg(response, false, "发送通知失败!但会议已新增成功");
									}
								}
								
							}
						}
					}
					this.addOrUpdateDistancelearning(obj, 1, 2, request, response);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			PrintUtil.printMsg(response, true, "会议新增成功!");
		} catch (Exception e) {
			e.printStackTrace();
			PrintUtil.printMsg(response, false, "会议新增失败!");
		}

	}

	@GetMapping
	@ApiOperation(value = "查询多条会议", notes = "三会一课列表")
	@ApiImplicitParams({ @ApiImplicitParam(name = "searchConferenceType", value = "会议类型", paramType = "query"),
			@ApiImplicitParam(name = "searchConferenceBeginDate", value = "会议开始时间", paramType = "query"),
			@ApiImplicitParam(name = "searchConferenceName", value = "会议名称", paramType = "query"),
			@ApiImplicitParam(name = "searchYear", value = "年份", paramType = "query"),
			@ApiImplicitParam(name = "searchQuarter", value = "季度", paramType = "query"),
			@ApiImplicitParam(name = "searchMeetingStatus", value = "会议状态", paramType = "query"),
			@ApiImplicitParam(name = "searchUserId", value = "当前登录用户测试使用", paramType = "query"),
			@ApiImplicitParam(name = "searchConferenceEndDate", value = "会议结束时间", paramType = "query") })
	public JsonQueryObject<Conference> getConferenceList(@ApiIgnore ConferenceQuery query, HttpServletRequest request,
			Model model) {
		// String u=LoginAuthUser.getSwbUserScopeTest(request);
		// query.setSearchScopeCode(u);
		String ip = request.getRemoteAddr();
		// 当前登录的用户
		LoginAuthUser loginu = LoginAuthUser.getUser(request);
		if (query.getSearchUserId() == null || "".equals(query.getSearchUserId())) {
			query.setSearchUserId(loginu.getEntityID());
		}
		if (query.getSearchYear() == null || "".equals(query.getSearchYear())) {
			query.setSearchYear(String.valueOf(DateUtil.getYear(new Date())));
		}
		try {
			List<Conference> list = conferenceService.getConferenceList(query);
			if (null != list && list.size() > 0) {
				for (Conference c : list) {
					Map params = new HashMap();
					params.put("groupId", c.getConferenceID());
					String resultList = remoteCallService.getForObject("fileListHandler", String.class, params);
					JSONObject json = JSONObject.parseObject(resultList).getJSONObject("data");
					JSONArray jsonList = json.getJSONArray("resultList");
					List<AttachementBean> ab = jsonList.toJavaList(AttachementBean.class);
					for (AttachementBean att : ab) {
						att.setImgUrl(UrlUtil.ATTACHEMEMENT_URL + att.getAttachid());
						if (PropertyUtil.objectNotEmpty(att.getAttachextname()) && DataUtil.isVideo(att.getAttachextname())) {
							att.setDefaultVideoUrl(DataUtil.videoImgUrl(att.getAttachid()));
						}else {
							att.setDefaultVideoUrl(UrlUtil.ATTACHEMEMENT_URL+AttachementBean.DEFAULT_VIDEO_ID);
						}
					}
					c.setFileList(ab);

					// 获取请假人员列表
					List<ConferenceUser> qjList = conferenceUserService.getConferenceUserQjList(c.getConferenceID());
					c.setQjList(qjList);
					// 获取缺席人员列表
					List<ConferenceUser> qxList = conferenceUserService.getConferenceUserQxList(c.getConferenceID());
					c.setQxList(qxList);
					// 获取考勤人员列表
					List<ConferenceUser> qdList = conferenceUserService.getConferenceUserQdList(c.getConferenceID());
					if (!qdList.isEmpty()) {
						c.setQdList(qdList);
					}
					// 获取出席人列表
					List<ConferenceUser> cxList = conferenceUserService.getConferenceUserCxList(c.getConferenceID());
					c.setConferenceUserList(cxList);

				}
			}
			query.setResultList(list);
			model.addAttribute("msg", "成功");
		} catch (Exception e) {
			e.printStackTrace();
			model.addAttribute("msg", "失败");
		}
		return new JsonQueryObject<>(query);
	}

	@GetMapping("/listConferenceByAdmin")
	@ApiOperation(value = "管理员查询多条会议", notes = "三会一课列表管理员")
	@ApiImplicitParams({ @ApiImplicitParam(name = "searchConferenceType", value = "会议类型", paramType = "query"),
			@ApiImplicitParam(name = "searchConferenceBeginDate", value = "会议开始时间", paramType = "query"),
			@ApiImplicitParam(name = "searchIshave", value = "是否存在附件", paramType = "query"),
			@ApiImplicitParam(name = "searchConferenceName", value = "会议名称", paramType = "query"),
			@ApiImplicitParam(name = "searchMeetingStatus", value = "会议状态", paramType = "query"),
			@ApiImplicitParam(name = "searchConferenceEndDate", value = "会议结束时间", paramType = "query") })
	public JsonQueryObject<Conference> getConferenceListByAdmin(@ApiIgnore ConferenceQuery query,
			HttpServletRequest request, Model model) {
		String u = LoginAuthUser.getScopeCodeByFunctionID(AuthorityInfoInit.shyk,request);
		query.setSearchScopeCode(u);
		LoginAuthUser user = LoginAuthUser.getUser(request);
		if (query.getSearchYear() == null || "".equals(query.getSearchYear())) {
			query.setSearchYear(String.valueOf(DateUtil.getYear(new Date())));
		}
		if (query.getSearchUserId() == null || "".equals(query.getSearchUserId())) {
			query.setSearchUserId(user.getEntityID());
		}
		List<Conference> list = conferenceService.getConferenceListMobileByAdmin(query);
		if (null != list && list.size() > 0) {
			for (Conference c : list) {
				Map params = new HashMap();
				params.put("groupId", c.getConferenceID());
				String resultList = remoteCallService.getForObject("fileListHandler", String.class, params);
				JSONObject json = JSONObject.parseObject(resultList).getJSONObject("data");
				JSONArray jsonList = json.getJSONArray("resultList");
				List<AttachementBean> ab = jsonList.toJavaList(AttachementBean.class);
				for (AttachementBean att : ab) {
					att.setImgUrl(UrlUtil.ATTACHEMEMENT_URL + att.getAttachid());
					if (PropertyUtil.objectNotEmpty(att.getAttachextname()) && DataUtil.isVideo(att.getAttachextname())) {
						att.setDefaultVideoUrl(DataUtil.videoImgUrl(att.getAttachid()));
					}else {
						att.setDefaultVideoUrl(UrlUtil.ATTACHEMEMENT_URL+AttachementBean.DEFAULT_VIDEO_ID);
					}
				}
				c.setFileList(ab);

				// 获取请假人员列表
				List<ConferenceUser> qjList = conferenceUserService.getConferenceUserQjList(c.getConferenceID());
				c.setQjList(qjList);
				// 获取缺席人员列表
				List<ConferenceUser> qxList = conferenceUserService.getConferenceUserQxList(c.getConferenceID());
				c.setQxList(qxList);
				// 获取考勤人员列表
				List<ConferenceUser> qdList = conferenceUserService.getConferenceUserQdList(c.getConferenceID());
				if (!qdList.isEmpty()) {
					c.setQdList(qdList);
				}
				// 获取出席人列表
				List<ConferenceUser> cxList = conferenceUserService.getConferenceUserCxList(c.getConferenceID());
				c.setConferenceUserList(cxList);

			}
		}
		query.setResultList(list);
		return new JsonQueryObject<>(query);
	}

	@PutMapping
	@ApiOperation(value = "更新会议记录", notes = "三会一课更新")
	public void updateConference(Conference obj, HttpServletRequest request, HttpServletResponse response,
			Model model) {
		String notice = request.getParameter("notice");
//		String notice = "1";//测试使用
		obj.setIsSend(notice);
		obj.setConferenceType(StringUtils.join(obj.getConferenceTypes(), ","));
		if (PropertyUtil.objectNotEmpty(obj.getUserIDs())) {
			List<ConferenceUser> existUserIDs = conferenceService.getExistUserIDs(obj.getUserIDs(), obj.getConferenceID());
			if (PropertyUtil.objectNotEmpty(existUserIDs)) {
				//把所有id存起来待删除所有其他的人员
				List<String> conferenceUserIDslist = new ArrayList(Arrays.asList(obj.getUserIDs()));
				String[] conferenceUserIDs = new String[conferenceUserIDslist.size()];
				conferenceUserIDslist.toArray(conferenceUserIDs);// list-->数组
				
				String[] userIDs = new String[existUserIDs.size()];
				for (int i = 0; i < existUserIDs.size(); i++) {
//					conferenceUserIDs[i] = existUserIDs.get(i).getConferenceUserID();
					userIDs[i] = existUserIDs.get(i).getUserID();
				}
				List<String> userIDslist = new ArrayList(Arrays.asList(userIDs));
				List<String> idslist = new ArrayList(Arrays.asList(obj.getUserIDs()));
				idslist.removeAll(userIDslist);
				String[] addUserIDs = new String[idslist.size()];
				idslist.toArray(addUserIDs);// list-->数组
				ConferenceUser conferenceUser = new ConferenceUser();
				conferenceUser.setConferenceID(obj.getConferenceID());
				conferenceUser.setPeopleNum(existUserIDs.size() + idslist.size());
				conferenceUser.setUserIDs(addUserIDs);
				conferenceService.addConferenceUser2(conferenceUser);
				if (null != conferenceUserIDs && conferenceUserIDs.length > 0) {
					conferenceService.deleteConferenceCorrelation(obj.getConferenceID(), conferenceUserIDs);
				}
			}else {
				ConferenceUser conferenceUser = new ConferenceUser();
				conferenceUser.setConferenceID(obj.getConferenceID());
				conferenceUser.setPeopleNum(obj.getUserIDs().length);
				conferenceUser.setUserIDs(obj.getUserIDs());
				conferenceService.addConferenceUser2(conferenceUser);
			}
		}
		// 查询已存在的数据
		if (obj.getPublishState() != null && obj.getPublishState() == 1) {
			// 发布时间
			obj.setPublishDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		}
		if (obj.getLastModifiedDate() == null || obj.getLastModifiedDate().equals("")) {
			// 最后修改时间
			obj.setLastModifiedDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			if (null != obj.getConferenceBeginDate() && !"".equals(obj.getConferenceBeginDate())) {
				Date conferenceBeginTime = sdf.parse(obj.getConferenceBeginDate());
				// 设置当前年份
				String year = String.valueOf(DateUtil.getYear(conferenceBeginTime));
				obj.setYear(year);
				// 设置季度
				obj.setQuarter(DateUtil.getSeason(conferenceBeginTime));
			}
			conferenceService.updateConference(obj);// 修改

			Conference conference = conferenceService.getConferenceById(obj.getConferenceID());
			if (!obj.getConferenceType().equals("5")) {
				// 执行发送通知的逻辑
				if (PropertyUtil.objectNotEmpty(conference.getIsSend()) && "1".equals(conference.getIsSend())) {
					if (conference.getPublishState() != null && conference.getPublishState().intValue() == 1) {
						LoginAuthUser user = LoginAuthUser.getUser(request);
						conference.setUserIDs(obj.getUserIDs());
						conference.setUserID(user.getEntityID());
						conference.setUserName(user.getName());
						ConferenceUser cu = new ConferenceUser();
						cu.setConferenceID(conference.getConferenceID());
						List<String> userIds = conferenceUserService.getConferenceUserIds(cu);
						if (!userIds.isEmpty()) {
							String[] iDs = new String[userIds.size()];
							userIds.toArray(iDs);// list-->数组
							conference.setUserIDs(iDs);
							if (!noticeService.sendNotice(conference, NoticeQuery.NOTICE_UPDATE)) {
								PrintUtil.printMsg(response, false, "发送通知失败!但会议更新完成");
							}
						}
						
					}
				}
			}
			try {
				if (conference.getConferenceType().equals("5")) {
					this.addOrUpdateDistancelearning(conference, 2, 1, request, response);
				}else if (conference.getConferenceType().contains("5"))  {
					this.addOrUpdateDistancelearning(conference, 2, 2, request, response);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			PrintUtil.printMsg(response, true, "会议更新成功!");
		} catch (Exception e) {
			PrintUtil.printMsg(response, false, "会议更新失败!");
		}

	}

	@GetMapping("/cancelConference")
	@ApiOperation(value = "取消/发布会议", notes = "取消/恢复三会一课")
	public void cancelConference(Model model,
			@ApiParam(value = "conferenceID", required = true) @RequestParam("conferenceID") String conferenceID,
			HttpServletResponse response) {
		Conference con = conferenceService.getConferenceById(conferenceID);
		Integer status = con.getPublishState();
		if (status != null && status == 1) {
			if (con.getIsSend() != null && "1".equals(con.getIsSend())) {
				ConferenceUser obj = new ConferenceUser();
				obj.setConferenceID(con.getConferenceID());
				List<String> userIds = conferenceUserService.getConferenceUserIds(obj);
				if (!userIds.isEmpty()) {
					String[] userIDs = new String[userIds.size()];
					userIds.toArray(userIDs);// list-->数组
					con.setUserIDs(userIDs);
					if (con.getConferenceType().equals("5")) {
						Distancelearning d = distancelearningService.getDisByID(obj.getConferenceID());
						d.setPublishState(ConferenceQuery.PUBLISHSTATE_NO);
						d.setPublishDate(new Date());
						distancelearningService.publishDistancelearning(d);
						if (!noticeService.sendDisNotice(d, NoticeQuery.NOTICE_CANCEL)) {
							PrintUtil.printMsg(response, false, "撤销会议时发送通知失败!");
						}
					}else {
						if (!noticeService.sendNotice(con, NoticeQuery.NOTICE_CANCEL)) {
							PrintUtil.printMsg(response, false, "撤销会议时发送通知失败!");
						}
					}
				}
			}
			if (conferenceService.cancelConferenceByID(conferenceID, 2)) {
				PrintUtil.printMsg(response, true, "会议撤销发布成功!");
			} else {
				PrintUtil.printMsg(response, false, "会议撤销发布失败!");
			}
		} else {
			if (con.getIsSend() != null && "1".equals(con.getIsSend())) {
				ConferenceUser obj = new ConferenceUser();
				obj.setConferenceID(con.getConferenceID());
				List<String> userIds = conferenceUserService.getConferenceUserIds(obj);
				if (!userIds.isEmpty()) {
					String[] userIDs = new String[userIds.size()];
					userIds.toArray(userIDs);// list-->数组
					con.setUserIDs(userIDs);
					if (con.getConferenceType().equals("5")) {
						Distancelearning d = distancelearningService.getDisByID(obj.getConferenceID());
						d.setPublishState(ConferenceQuery.PUBLISHSTATE_YES);
						distancelearningService.updateDistancelearning(d);
						if (!noticeService.sendDisNotice(d, NoticeQuery.NOTICE_UPDATE)) {
							PrintUtil.printMsg(response, false, "发布会议时发送通知失败!");
						}
					}else {
						if (!noticeService.sendNotice(con, NoticeQuery.NOTICE_UPDATE)) {
							PrintUtil.printMsg(response, false, "发布会议时发送通知失败!");
						}
					}
				}
			}
			if (conferenceService.cancelConferenceByID(conferenceID, 1)) {
				PrintUtil.printMsg(response, true, "会议发布成功!");
			} else {
				PrintUtil.printMsg(response, false, "会议发布失败!");
			}
		}
	}

	@PutMapping("/updateReceipt")
	@ApiOperation(value = "回执操作/请假", notes = "对三会一课的回执操作")
	public void updateReceipt(ConferenceUser obj, HttpServletRequest request, HttpServletResponse response,
			Model model) {
		// 回执时间
		LoginAuthUser u = LoginAuthUser.getUser(request);
		if (!PropertyUtil.objectNotEmpty(obj.getUserID())) {
			obj.setUserID(u.getEntityID());
		}
		obj.setReceiptDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		ConferenceUser cu = conferenceUserService.getConferenceUser(obj);
		if (cu == null) {
			if (obj.getReceiptType().intValue() == 3) {
				PrintUtil.printMsg(response, false, "您未参加此会议,不能进行请假!");
			} else {
				PrintUtil.printMsg(response, false, "您未参加此会议,不能进行回执!");
			}
		} else {
			if (PropertyUtil.objectNotEmpty(cu.getReceiptType()) && cu.getReceiptType().intValue() == ConferenceQuery.STATUS_QJ) {
				PrintUtil.printMsg(response, false, "您已进行过请假，请勿重复进行请假!");
			}else {
				Boolean bl = conferenceUserService.updateReceipt(obj);
				if (null != obj.getReceiptType() && obj.getReceiptType() == 3) {
					// 通过关系表id确定是否存在考勤记录
					List<ConferenceAttendance> attendanceList = conferenceAttendanceService
							.getConferenceAttendanceList(cu.getConferenceUserID());
					if (!attendanceList.isEmpty()) {
						conferenceAttendanceService.deleteConferenceAttendance(cu.getConferenceUserID());
					}
				}
				if (bl) {
					if (obj.getReceiptType().intValue() == 3) {
						PrintUtil.printMsg(response, true, "请假成功!");
					} else {
						PrintUtil.printMsg(response, true, "操作成功!");
					}
				}else {
					if (obj.getReceiptType().intValue() == 3) {
						PrintUtil.printMsg(response, false, "请假失败!");
					} else {
						PrintUtil.printMsg(response, false, "操作失败!");
					}
				}
			}
		}
	}
	//测试
//	@GetMapping("/updateReceiptcs")
//	@ApiOperation(value = "回执操作/请假", notes = "对三会一课的回执操作")
//	public void updateReceiptcs(ConferenceUser obj, HttpServletRequest request, HttpServletResponse response,
//			Model model) {
//		// 回执时间
//		LoginAuthUser u = LoginAuthUser.getUser(request);
//		if (!PropertyUtil.objectNotEmpty(obj.getUserID())) {
//			obj.setUserID(u.getEntityID());
//		}
//		obj.setReceiptDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
//		ConferenceUser cu = conferenceUserService.getConferenceUser(obj);
//		if (cu == null) {
//			if (obj.getReceiptType().intValue() == 3) {
//				PrintUtil.printMsg(response, false, "您未参加此会议,不能进行请假!");
//			} else {
//				PrintUtil.printMsg(response, false, "您未参加此会议,不能进行回执!");
//			}
//		} else {
//			try {
//				conferenceUserService.updateReceipt(obj);
//				if (null != obj.getReceiptType() && obj.getReceiptType() == 3) {
//					// 通过关系表id确定是否存在考勤记录
//					List<ConferenceAttendance> attendanceList = conferenceAttendanceService
//							.getConferenceAttendanceList(cu.getConferenceUserID());
//					if (!attendanceList.isEmpty()) {
//						conferenceAttendanceService.deleteConferenceAttendance(cu.getConferenceUserID());
//					}
//				}
//				if (obj.getReceiptType().intValue() == 3) {
//					PrintUtil.printMsg(response, true, "请假成功!");
//				} else {
//					PrintUtil.printMsg(response, true, "操作成功!");
//				}
//			} catch (Exception e) {
//				e.printStackTrace();
//				PrintUtil.printMsg(response, false, "操作失败,请联系管理员!");
//			}
//		}
//	}
	@GetMapping("/getDate")
	@ApiOperation(value = "二维码生成获取当前时间", notes = "二维码生成获取当前时间")
	public JsonSuccessObject<String> getDate(HttpServletRequest request, HttpServletResponse response, Model model) {
		String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
		JsonSuccessObject<String> returnResult = new JsonSuccessObject<>(format);
		return returnResult;
	}

	@PostMapping("/addAttendance")
	@ApiOperation(value = "考勤记录", notes = "对三会一课的考勤记录")
	public void addAttendance(ConferenceAttendance obj, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		LoginAuthUser u = LoginAuthUser.getUser(request);
		// if (!PropertyUtil.objectNotEmpty(obj.getUserID())) {
		// obj.setUserID(u.getEntityID());
		// }
		if (!PropertyUtil.objectNotEmpty(obj.getUserIDs())) {
			String[] userID = { u.getEntityID() };
			obj.setUserIDs(userID);
		}
		obj.setAttendanceDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		if (obj.getAttendanceStatus() == null) {
			obj.setAttendanceStatus(ConferenceQuery.STATUS_YQ);
		}
		// 获取用户与记录的关系表 存入考勤表中
		ConferenceUser conferenceUser = new ConferenceUser();
		conferenceUser.setConferenceID(obj.getConferenceID());
		conferenceUser.setUserIDs(obj.getUserIDs());
		List<ConferenceUser> cuList = conferenceUserService.getConferenceUserToAtt(conferenceUser);
		if (PropertyUtil.objectNotEmpty(cuList)) {
			if (PropertyUtil.objectNotEmpty(obj.getUserIDs()) && obj.getUserIDs().length == 1) {//扫描二维码签到
				List<ConferenceAttendance> idsList = conferenceAttendanceService.getConferenceAttendanceByUserIdsList(cuList);
				if (PropertyUtil.objectNotEmpty(idsList)) {
					PrintUtil.printMsg(response, false, "已经进行过签到，请勿重复签到!");
				}else {
					if (PropertyUtil.objectNotEmpty(obj.getViaTime())) {
						Date date = sdf.parse(obj.getViaTime());
						long minute = DateUtil.getMinute(new Date(), date);
						if (minute >= 5) {
							PrintUtil.printMsg(response, false, "二维码已过期!");
						} else {
							try {
								this.signLogic(cuList, conferenceUser, obj,1);
								PrintUtil.printMsg(response, true, "签到成功!");
							} catch (Exception e) {
								PrintUtil.printMsg(response, false, "签到失败!");
							}
						}
					} else {
						try {
							this.signLogic(cuList, conferenceUser, obj,1);
							PrintUtil.printMsg(response, true, "签到成功!");
						} catch (Exception e) {
							PrintUtil.printMsg(response, false, "签到失败!");
						}
					}
				}
			}else {//点名签到
				try {
					this.signLogic(cuList, conferenceUser, obj,2);
					PrintUtil.printMsg(response, true, "签到成功!");
				} catch (Exception e) {
					PrintUtil.printMsg(response, false, "签到失败!");
				}
			}
		}else {
			PrintUtil.printMsg(response, false, "您没有参加此会议，无法进行签到！");
		}
	}

	
	public void signLogic(List<ConferenceUser> cuList,ConferenceUser conferenceUser,ConferenceAttendance obj,Integer i) throws Exception {
		for (ConferenceUser cu : cuList) {
			// 签到时更新一下回执表,以防存在请假
			if (cu.getReceiptType() != null && cu.getReceiptType().intValue() == 3) {
				conferenceUser.setReceiptType(ConferenceQuery.STATUS_YQ);
				conferenceUser.setUserID(cu.getUserID());
				conferenceUserService.updateReceipt(conferenceUser);
			}
			if (i.intValue() == 1) {
				obj.setConferenceUserID(cu.getConferenceUserID());
				conferenceAttendanceService.addConferenceAttendance(obj);
			}else {
				// 通过关系表id确定是否存在考勤记录
				List<ConferenceAttendance> attendanceList = conferenceAttendanceService
						.getConferenceAttendanceList(cu.getConferenceUserID());
				// 只存在一条考勤记录时
				if (attendanceList.isEmpty()) {// 判断是否有考勤记录
					obj.setConferenceUserID(cu.getConferenceUserID());
					conferenceAttendanceService.addConferenceAttendance(obj);
				} else {
					obj.setConferenceUserID(cu.getConferenceUserID());
					conferenceAttendanceService.updateConferenceAttendance(obj);
				}
			}
		}
	}
	
	@GetMapping("/{id}")
	@ApiOperation(value = "根据主键查询会议记录", notes = "会议详情")
	public JsonSuccessObject<Conference> getConference(Model model,
			@ApiParam(value = "conferenceID", required = false) @PathVariable("id") String id,
			HttpServletRequest request) {
		Conference obj = new Conference();
		obj.setConferenceID(id);
		LoginAuthUser u = LoginAuthUser.getUser(request);
		obj.setUserID(u.getEntityID());
		Conference conference = conferenceService.getConference(obj);
		// 获取附件信息
		Map params = new HashMap();
		params.put("groupId", conference.getConferenceID());
		String resultList = remoteCallService.getForObject("fileListHandler", String.class, params);
		JSONObject json = JSONObject.parseObject(resultList).getJSONObject("data");
		JSONArray jsonList = json.getJSONArray("resultList");
		List<AttachementBean> ab = jsonList.toJavaList(AttachementBean.class);
		for (AttachementBean att : ab) {
			att.setImgUrl(UrlUtil.ATTACHEMEMENT_URL + att.getAttachid());
			if (PropertyUtil.objectNotEmpty(att.getAttachextname()) && DataUtil.isVideo(att.getAttachextname())) {
				att.setDefaultVideoUrl(DataUtil.videoImgUrl(att.getAttachid()));
			}else {
				att.setDefaultVideoUrl(UrlUtil.ATTACHEMEMENT_URL+AttachementBean.DEFAULT_VIDEO_ID);
			}
		}
		conference.setFileList(ab);
		// 获取请假人员列表
		List<ConferenceUser> qjList = conferenceUserService.getConferenceUserQjList(id);
		conference.setQjList(qjList);
		// 获取缺席人员列表
		List<ConferenceUser> qxList = conferenceUserService.getConferenceUserQxList(id);
		conference.setQxList(qxList);
		// 获取考勤人员列表
		List<ConferenceUser> qdList = conferenceUserService.getConferenceUserQdList(id);
		if (!qdList.isEmpty()) {
			conference.setQdList(qdList);
		}
		// 获取出席人列表
		List<ConferenceUser> cxList = conferenceUserService.getConferenceUserCxList(id);
		conference.setConferenceUserList(cxList);
		JsonSuccessObject<Conference> returnResult = new JsonSuccessObject<>(conference);
		return returnResult;
	}

	@GetMapping("/listGetConference")
	@ApiOperation(value = "获取会议出席人列表", notes = "出席人列表查询")
	@ApiImplicitParams({ @ApiImplicitParam(name = "searchConferenceID", value = "会议id", paramType = "query") })
	public JsonQueryObject<ConferenceUser> getConferenceList(@ApiIgnore ConferenceUserQuery query,
			HttpServletRequest request, Model model) {
		try {
			List<ConferenceUser> userList = conferenceUserService.getConferenceUserList(query);
			query.setResultList(userList);
			model.addAttribute("msg", "成功");
		} catch (Exception e) {
			e.printStackTrace();
			model.addAttribute("msg", "失败");
		}
		return new JsonQueryObject<>(query);
	}

	@GetMapping("/activeConference")
	@ApiOperation(value = "启用/未启用会议操作", notes = "启用/未启用会议操作")
	public void activeConference(Conference obj, HttpServletRequest request, Model model,
			HttpServletResponse response) {
		try {
			conferenceService.activeConference(obj);
			PrintUtil.printMsg(response, true, "操作成功!");
		} catch (Exception e) {
			e.printStackTrace();
			PrintUtil.printMsg(response, false, "操作失败!");
		}
	}

	@GetMapping("/getUserScope")
	@ApiOperation(value = "获取登录人code", notes = "获取登录人code")
	public JsonSuccessObject<String> getUserCode(HttpServletRequest request) {
		String u = LoginAuthUser.getScopeCodeByFunctionID(AuthorityInfoInit.zbq,request);
		JsonSuccessObject<String> returnResult = new JsonSuccessObject<String>(u);
		return returnResult;
	}

	/**
	 * @date 2018年6月25日 上午9:42:05
	 * @author hanxiangyu
	 * @param conferenceStat
	 * @param request
	 * @param model
	 * @return
	 */
	@GetMapping("/getPartyOrganizationRank")
	@ApiOperation(value = "三会一课统计", notes = "三会一课统计")
	@ApiImplicitParams({ @ApiImplicitParam(name = "searchBeginDate", value = "开始时间", paramType = "query"),
			@ApiImplicitParam(name = "searchEndDate", value = "结束时间", paramType = "query"),
			@ApiImplicitParam(name = "searchPartyBranch", value = "所在党支部", paramType = "query"),
			@ApiImplicitParam(name = "searchYear", value = "年份", paramType = "query"),
			@ApiImplicitParam(name = "searchType", value = "类型", paramType = "query"),
			@ApiImplicitParam(name = "isUserAdmin", value = "是否是管理员", paramType = "query"),
			@ApiImplicitParam(name = "searchQuarter", value = "季度", paramType = "query") })
	public JsonQueryObject<ConferenceStat> getPartyOrganizationRank(@ApiIgnore ConferenceStatQuery query,
			HttpServletRequest request, Model model) {
		String u = LoginAuthUser.getScopeCodeByFunctionID(AuthorityInfoInit.zbq,request);// 前台获去code
		LoginAuthUser user = LoginAuthUser.getUser(request);
		query.setSearchScopeCode(u);
		query.setSearchUserID(user.getEntityID());
		if (query.getSearchYear() == null || "".equals(query.getSearchYear())) {
			query.setSearchYear(String.valueOf(DateUtil.getYear(new Date())));
		}
		List<ConferenceStat> list = null;
//		Integer isManager = Integer.valueOf(request.getParameter("isUserAdmin"));
		if (!PropertyUtil.objectNotEmpty(query.getIsUserAdmin())) {
			query.setIsUserAdmin(ConferenceQuery.ONE);
		}
		if (query.getIsUserAdmin().intValue() == 1) {// 管理员查询
			list = conferenceStatService.getPartyOrganizationByAdmin(query);
		} else {
			list = conferenceStatService.getPartyOrganizationRank(query);
		}
		query.setResultList(list);
		return new JsonQueryObject<>(query);
	}

	/**
	 * 删除会议
	 * 
	 * @date 2018年7月8日 上午11:33:19
	 * @author hanxiangyu
	 * @param ids
	 * @param response
	 */

	@DeleteMapping("/deleteConference")
	@ApiOperation(value = "删除会议", notes = "删除三会一课")
	public void deleteConference(@ApiParam(value = "conferenceIDs", required = true) @RequestParam("ids") String[] ids,
			HttpServletResponse response) {
		if (null != ids && ids.length > 0) {
			for (String id : ids) {
				Distancelearning dis = distancelearningService.getDisByID(id);
				if (null != dis) {
					dis.setActiveState(2);
					dis.setLastModifiedDate(new Date());
					distancelearningService.updateDisById(dis);
				}
			}
		}
		if (conferenceService.deleteConference(ids)) {
			PrintUtil.printMsg(response, true, "删除成功!");
		} else {
			PrintUtil.printMsg(response, false, "删除失败");
		}

	}

	@PostMapping("/updateConferenceImg")
	@ApiOperation(value = "更新/新增会议图片", notes = "更新/新增会议图片")
	public void updateConferenceImg(Conference obj, HttpServletRequest request, HttpServletResponse response) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		obj.setLastModifiedDate(sdf.format(new Date()));
		try {
			conferenceService.updateConference(obj);
			PrintUtil.printMsg(response, true, "更新成功!");
		} catch (Exception e) {
			e.printStackTrace();
			PrintUtil.printMsg(response, false, "更新失败");
		}
	}

	@GetMapping("/getAttenanceStat")
	@ApiOperation(value = "出勤情况统计", notes = "当前登录人考勤情况统计")
	public JsonSuccessObject<ConferenceStat> getAttenanceStat(ConferenceStat conferenceStat, HttpServletRequest request,
			Model model) {
		LoginAuthUser loginu = LoginAuthUser.getUser(request);
		String scope = LoginAuthUser.getScopeCodeByFunctionID(AuthorityInfoInit.zbq,request);
		conferenceStat.setScopeCode(scope);
		if (conferenceStat.getUserID() == null || "".equals(conferenceStat.getUserID())) {
			conferenceStat.setUserID(loginu.getEntityID());
		}
		if (conferenceStat.getYear() == null || "".equals(conferenceStat.getYear())) {
			conferenceStat.setYear(String.valueOf(DateUtil.getYear(new Date())));
		}
		ConferenceStat attenanceStat = conferenceStatService.getAttenanceStat(conferenceStat);
		JsonSuccessObject<ConferenceStat> returnResult = new JsonSuccessObject<>(attenanceStat);
		return returnResult;
	}

	@GetMapping("/getBranchStudy")
	@ApiOperation(value = "本支部组织会议统计分析", notes = "获取本支部组织会议统计分析情况")
	public JsonQueryObject<ConferenceStat> getBranchStudy(@ApiIgnore ConferenceStatQuery query,
			HttpServletRequest request, Model model) {
		String u = LoginAuthUser.getScopeCodeByFunctionID(AuthorityInfoInit.zbq,request);
		LoginAuthUser loginu = LoginAuthUser.getUser(request);
		query.setSearchUserID(loginu.getEntityID());
		query.setSearchScopeCode(u);
		if (query.getSearchYear() == null || "".equals(query.getSearchYear())) {
			query.setSearchYear(String.valueOf(DateUtil.getYear(new Date())));
		}
		List<ConferenceStat> list = conferenceStatService.getBranchStudy(query);
		query.setResultList(list);
		return new JsonQueryObject<>(query);
	}

	@PostMapping("/startAndEndConference")
	@ApiOperation(value = "开始和结束会议", notes = "开始和结束会议")
	public void startAndEndConference(ConferenceBean obj, HttpServletResponse response) {
		if (conferenceService.startAndEndConference(obj)) {
			if (obj.getStates().intValue() == 1) {
				PrintUtil.printMsg(response, true, "开始会议成功!");
			} else {
				PrintUtil.printMsg(response, true, "结束会议成功!");
			}
			Conference con = conferenceService.getConferenceById(obj.getConferenceID());
			if (con.getConferenceType().contains("5")) {
				DistancelearningBean disBean = new DistancelearningBean();
				disBean.setDistancelearningID(obj.getConferenceID());
				disBean.setStates(obj.getStates());
				distancelearningService.startAndEndDis(disBean);
			}
		} else {
			if (obj.getStates().intValue() == 1) {
				PrintUtil.printMsg(response, false, "开始会议失败!");
			} else {
				PrintUtil.printMsg(response, false, "结束会议失败!");
			}
		}

	}

	@GetMapping("/findConferenceListByOrgId")
	@ApiOperation(value = "根据支部id查询会议", notes = "根据支部id查询会议")
	@ApiImplicitParams({ @ApiImplicitParam(name = "searchConferenceType", value = "会议类型", paramType = "query"),
			@ApiImplicitParam(name = "searchConferenceBeginDate", value = "会议开始时间", paramType = "query"),
			@ApiImplicitParam(name = "searchConferenceName", value = "会议名称", paramType = "query"),
			@ApiImplicitParam(name = "searchYear", value = "年份", paramType = "query"),
			@ApiImplicitParam(name = "searchOrganizationId", value = "支部id", paramType = "query"),
			@ApiImplicitParam(name = "searchQuarter", value = "季度", paramType = "query"),
			@ApiImplicitParam(name = "searchMeetingStatus", value = "会议状态", paramType = "query"),
			@ApiImplicitParam(name = "searchConferenceEndDate", value = "会议结束时间", paramType = "query") })
	public JsonQueryObject<Conference> getConferenceListByOrgId(@ApiIgnore ConferenceQuery query,
			HttpServletRequest request, Model model) {
		// String u=LoginAuthUser.getSwbUserScopeTest(request);
		// query.setSearchScopeCode(u);
		String ip = request.getRemoteAddr();
		// 当前登录的用户
		LoginAuthUser loginu = LoginAuthUser.getUser(request);
		if (query.getSearchUserId() == null || "".equals(query.getSearchUserId())) {
			query.setSearchUserId(loginu.getEntityID());
		}
		if (query.getSearchYear() == null || "".equals(query.getSearchYear())) {
			query.setSearchYear(String.valueOf(DateUtil.getYear(new Date())));
		}
		try {
			List<Conference> list = conferenceService.getConferenceListByOrgId(query);
			if (null != list && list.size() > 0) {
				for (Conference c : list) {
					Map params = new HashMap();
					params.put("groupId", c.getConferenceID());
					String resultList = remoteCallService.getForObject("fileListHandler", String.class, params);
					JSONObject json = JSONObject.parseObject(resultList).getJSONObject("data");
					JSONArray jsonList = json.getJSONArray("resultList");
					List<AttachementBean> ab = jsonList.toJavaList(AttachementBean.class);
					for (AttachementBean att : ab) {
						att.setImgUrl(UrlUtil.ATTACHEMEMENT_URL + att.getAttachid());
						if (PropertyUtil.objectNotEmpty(att.getAttachextname()) && DataUtil.isVideo(att.getAttachextname())) {
							att.setDefaultVideoUrl(DataUtil.videoImgUrl(att.getAttachid()));
						}else {
							att.setDefaultVideoUrl(UrlUtil.ATTACHEMEMENT_URL+AttachementBean.DEFAULT_VIDEO_ID);
						}
					}
					c.setFileList(ab);
				}
			}
			query.setResultList(list);
			model.addAttribute("msg", "成功");
		} catch (Exception e) {
			e.printStackTrace();
			model.addAttribute("msg", "失败");
		}
		return new JsonQueryObject<>(query);
	}

	/**
	 * 创建三会一课是新增或修改三会一课
	 * @date 2018年11月22日 上午9:57:21 
	 * @author hanxiangyu
	 * @param conference 三会一课bean
	 * @param type 类型
	 * @param isNotice 是否通知
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	// 当创建会议类型包含远程教育时添加远程教育
	public void addOrUpdateDistancelearning(Conference conference, int type,int isNotice, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Distancelearning obj = new Distancelearning();
		if (PropertyUtil.objectNotEmpty(conference.getUserIDs())) {
			obj.setUserIDs(conference.getUserIDs());// 用户id
		}
		if (PropertyUtil.objectNotEmpty(conference.getConferenceID())) {
			obj.setDistancelearningID(conference.getConferenceID());
		}
		if (PropertyUtil.objectNotEmpty(conference.getConferenceBeginDate())) {
			obj.setBeginDate(conference.getConferenceBeginDate());// 开始时间
		}
		if (PropertyUtil.objectNotEmpty(conference.getConferenceEndDate())) {
			obj.setEndDate(conference.getConferenceEndDate());// 结束时间
		}
		if (PropertyUtil.objectNotEmpty(conference.getConferenceName())) {
			obj.setDistancelearningName(conference.getConferenceName());// 名称
		}
		if (PropertyUtil.objectNotEmpty(conference.getConferencePresentation())) {
			obj.setDistancelearningPresentation(conference.getConferencePresentation());// 简介
		}
		if (PropertyUtil.objectNotEmpty(conference.getIsSend())) {
			obj.setIsSend(conference.getIsSend());// 是否通知
		}
		if (PropertyUtil.objectNotEmpty(conference.getConferenceSite())) {
			obj.setDistancelearningSite(conference.getConferenceSite());// 会议地点
		}
		if (PropertyUtil.objectNotEmpty(conference.getCreateDate())) {
			obj.setCreateDate(sdf.parse(conference.getCreateDate()));// 创建时间
		}
		if (PropertyUtil.objectNotEmpty(conference.getPublishState())) {
			obj.setPublishState(conference.getPublishState());// 发布状态
		}
		if (PropertyUtil.objectNotEmpty(conference.getActiveState())) {
			obj.setActiveState(conference.getActiveState());
		}
		
		if (PropertyUtil.objectNotEmpty(conference.getDefaultImageId())) {
			obj.setDefaultImageId(conference.getDefaultImageId());// 封面图
		}
		if (PropertyUtil.objectNotEmpty(conference.getCompere())) {
			obj.setCompere(conference.getCompere());// 主持人
		}
		if (PropertyUtil.objectNotEmpty(conference.getOrganizationId())) {
			obj.setOrganizationId(conference.getOrganizationId());// 机构id
		}
		obj.setDisType("ycjy");// 类型
		obj.setEditState(2);
		LoginAuthUser u = LoginAuthUser.getUser(request);
		if (PropertyUtil.objectNotEmpty(conference.getUserID())) {
			obj.setUserID(conference.getUserID());// 发布人id
		}else {
			obj.setUserID(u.getEntityID());// 发布人id
		}
		if (PropertyUtil.objectNotEmpty(conference.getUserName())) {
			obj.setUserName(conference.getUserName());// 发布人姓名
		}else {
			obj.setUserName(u.getName());// 发布人姓名
		}
		if (PropertyUtil.objectNotEmpty(conference.getYear())) {
			obj.setYear(conference.getYear());
		}
		if (PropertyUtil.objectNotEmpty(conference.getQuarter())) {
			obj.setQuarter(conference.getQuarter());
		}
		// obj.setActiveState(DistancelearningQuery.ACTIVESTATE_YES);//默认启用
		if (obj.getPublishState() == null) {
			obj.setPublishState(DistancelearningQuery.PUBLISHSTATE_NO);// 默认未发布
		}
		if (obj.getPublishState() != null && obj.getPublishState() == 1) {
			// 发布时间
			obj.setPublishDate(new Date());
		}
		Distancelearning distancelearning = distancelearningService.getDisByID(obj.getDistancelearningID());
		if (PropertyUtil.objectNotEmpty(distancelearning)) {
			distancelearningService.updateDistancelearning(obj);
			if (PropertyUtil.objectNotEmpty(isNotice) && isNotice == 1) {
				if (PropertyUtil.objectNotEmpty(obj.getIsSend()) && "1".equals(obj.getIsSend())
						&& obj.getPublishState().intValue() == ConferenceQuery.PUBLISHSTATE_YES) {
					if (!noticeService.sendDisNotice(distancelearning, NoticeQuery.NOTICE_UPDATE)) {
						PrintUtil.printMsg(response, false, "修改会议时发送通知失败!但会议已更新");
					}
				}
			}
		} else {
			// 新增
			distancelearningService.addDistancelearning(obj);
			if (obj.getUserIDs() != null && obj.getUserIDs().length > 0) {
				distancelearningService.addDistancelearningUser(obj);
			}
			if (obj.getCourseIDs() != null && obj.getCourseIDs().length > 0) {
				distancelearningService.addDistancelearningCourse(obj);
			}
			if (PropertyUtil.objectNotEmpty(isNotice) && isNotice == 1) {
				if (PropertyUtil.objectNotEmpty(obj.getIsSend()) && "1".equals(obj.getIsSend())
						&& obj.getPublishState().intValue() == ConferenceQuery.PUBLISHSTATE_YES) {
					if (!noticeService.sendDisNotice(obj, NoticeQuery.NOTICE_ADD)) {
						PrintUtil.printMsg(response, false, "新增会议时发送通知失败!但会议已新增完成");
					}
				}
			}
		}
	}
	
	
}
